package com.richapp.launcher.control;

import android.content.Context;
import android.media.AudioManager;
import android.util.Log;

import java.util.ResourceBundle;

/**
 * Created by jack on 2015/3/23 0023.
 */
public class VolumeControl {

    private static VolumeControl audioControl;
    private Context context;

    private int lastVol = 25;

    private CustomSysSettingManager customSysSettingManager = null;
    private VolumeControl(){

    }

    public static VolumeControl getInstance(){
        if(audioControl == null){
            audioControl = new VolumeControl();
        }
        return audioControl;
    }

    //静音
    public void setNoSounds(){
        //String command = "input keyevent VOLUME_MUTE";
        ControlProcess.getInstance().doCommand(8);
        Log.d("TEST", "静音操作");
    }

    //静音恢复
    public void setNoSoundsReset(){
        //String command = "input keyevent VOLUME_MUTE";
        ControlProcess.getInstance().doCommand(8);
        Log.d("TEST", "静音恢复");
    }

    //来电音量调节
    public void callSounds(){
        lastVol = customSysSettingManager.getCurrentVolume(CustomSysSettingManager.SoundType.Music);
        customSysSettingManager.setVolume(CustomSysSettingManager.SoundType.Music, 25);
        Log.d("TEST", "来电音量调节");
    }

    //来电音量调节恢复
    public void callSoundsReset(){
        customSysSettingManager.setVolume(CustomSysSettingManager.SoundType.Music,lastVol);
        Log.d("TEST", "来电音量调节恢复");
    }

    //判断是否在播放音乐或者播放视频
    public boolean isAudioOrMediaPlay(){
        return customSysSettingManager.isAudioOrMediaPlay();
    }

    //加音量
    public void addSounds(){
        //String command = "input keyevent VOLUME_UP";
        ControlProcess.getInstance().doCommand(10);
        Log.d("TEST","加音量操作");
    }

    //减音量
    public void delSounds(){
        //String command = "input keyevent VOLUME_DOWN";
        ControlProcess.getInstance().doCommand(11);
        Log.d("TEST","减音量操作");
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
        customSysSettingManager = new CustomSysSettingManager(context);
    }
}
